# -*- coding: utf-8 -*-
# @Time     : 2021/4/19 10:36
# @Author   : pengrenjie
# @Email    : 941257162@.com
# @File     : ATM取款老师版本.py
#atm系统
#登录
    #取钱
    #存钱
    #查询
    #退出
user = {"root":{"passwd":"123456","money":2000},"admin":{"passwd":"admin","money":1000}}


def login(username,passwd):
    try:
        if username in user and user.get(username).get("passwd")==passwd:
            print("登陆成功".center(50,'*'))
            return 1
        else:
            print("登陆失败".center(50*'*'))

    except  Exception:
        print("登陆失败".center(50,'*'))
def menu():
    print("1.取钱".center(20," "))
    print("2.存钱".center(20, " "))
    print("3.查询".center(20, " "))
    print("4.退出".center(20," "))
    num  = input("请输入你的选择:")
    return num

#取钱
def get_money(usrname,money):
    m1 = user.get(usrname).get("money")
    if m1 > money:
        user[usrname]["money"] = m1 - money
        print("取钱成功")
    else:
        print("余额不足！！！，无法交易")
#存钱
def put_money(username,money):
    m2 = user.get(username).get("money")
    user[username]["money"] = m2 + money
    print("存钱成功")

#查询
def check_money(username):
     m3 = user.get(username).get("money")

     print(m3)

print("欢迎来到三创atm".center(50,'*'))
username = input("请输入用户名：")
passwd = input("请输入密码：")

login_status = login(username,passwd)

if login_status == 1:
    # login(username,passwd)
    while 1:
        choice = menu()
        if choice == '1':
            money = input("请输入要取款的金额：")
            get_money(username,int(money))
        elif choice == '2':
            money2 = input("请输入要存钱的金额：")
            put_money(username,int(money))
        elif choice == '3':
            check_money(username)
        elif choice == '4':
            exit()



